new Vue({
  el: '#app',
  data: {
    ossImgUrl: ossImgUrl,//oss图片域名
    screenHeight: document.documentElement.clientHeight,     // 当前高度
    originHeight: document.documentElement.clientHeight,     //默认高度，用作比较
    isOriginHeight: true,    //当前高度是否仍等于默认高度
    user_phone: "",//法人手机号
    enp_title: "",//企业名称
    enp_code: "",//企业信用代码
    enp_user: "",//法人
    auth_status: "",//	0 未认证 1 认证中 2 认证失败 3 认证成功（仅适用于大陆）
    flag: false//下一步是否可点击
  },
  watch: {
    screenHeight(val) {
      if (this.originHeight - val > 60) {    //这里以防万一改了下判断形式，当屏幕高度减少了60px以上时才隐藏footer
        this.isOriginHeight = false;
      } else {
        this.isOriginHeight = true;
      }
    }
  },
  created() {
    if (getUrlParam("user_phone")) {
      local.set('user_phone', getUrlParam("user_phone"));
    }
    // 缓存小程序传来的 phone 参数（请求头用）
    if (getUrlParam("phone")) {
      local.set("phone", getUrlParam("phone"));
    }
  },
  mounted() {
    // 解决底部被键盘顶起的问题
    window.onresize = () => {
      return (() => {
        this.screenHeight = document.documentElement.clientHeight;
      })()
    }
    // 查询数据
    this.queryAuthStatus();
  },
  methods: {
    // 查询法人授权书签署状态
    queryAuthStatus: function () {
      var that = this;
      get("api/enps/auth_book").then(function (res) {
        that.user_phone = res.data.user_phone;
        that.enp_title = res.data.enp_title;
        that.enp_code = res.data.enp_code;
        that.enp_user = res.data.enp_user;
        that.auth_status = res.data.auth_status;
        switch (that.auth_status) {
          case 0://未认证
            // 留在当前页
            break;
          case 1://认证中
            window.location.href = "legalRz_sq.html";
            break;
          case 2://认证失败
            window.location.href = "legalRz_sb.html";
            break;
          case 3://认证成功
            window.location.href = "legalRz_tg.html";
            break;
        }
        that.mustClick();
      })
    },
    // 失去焦点验证下一步是否可点击
    mustClick: function () {
      if (!this.user_phone) {
        this.flag = false;
      } else {
        this.flag = true;
      }
    },
    // 下一步
    submit: function () {
      var that = this;
      if (!this.flag || this.auth_status != 0) { return }
      post("api/enps/auth/put", {
        user_phone: this.user_phone.replace(/\s*/g, "")
      }).then(function (res) {
        window.location.href = "legalRz_sq.html";
      })
    }
  },
})